/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Finder.java
 *
 * Created on Oct 16, 2011, 1:23:49 PM
 */
package azhar.view.control;

import azhar.com.TableOperation;
import azhar.view.Main;
import java.util.ArrayList;
import javax.swing.JPopupMenu;
import javax.swing.JTable;
import javax.swing.RowFilter;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;

/**
 *
 * @author Al-Insan
 */
public class Finder extends javax.swing.JPanel {

    private Main main;
    private JPopupMenu pop;
    private CreateMessage message;
    private ArrayList data;
    private TableOperation tabOp;

    /** Creates new form Finder */
    public Finder(Main m, JPopupMenu popup, CreateMessage cm) {
        initComponents();
        main = m;
        pop = popup;
        message = cm;
        tabOp = new TableOperation();
        initTable();
        initGroupActions();
        initGuruActions();
        initKaryawanActions();
        initSiswaActions();
    }

    public void initTable() {
        tableGuru.setModel(main.tabContact.getGuruModel());
        tableSiswa.setModel(main.tabContact.getSiswaModel());
        tableKaryawan.setModel(main.tabContact.getKaryawanModel());
        DefaultTableModel model = (DefaultTableModel) tableGroup.getModel();
        tableGroup.setModel(model);
        model.addRow(new Object[]{"1", "Guru TK", "Group ini berisi seluruh contact person dari guru TK"});
        model.addRow(new Object[]{"2", "Guru SD", "Group ini berisi seluruh contact person dari guru SD"});
        model.addRow(new Object[]{"3", "Guru SMP", "Group ini berisi seluruh contact person dari guru SMP"});
        int k = 0;
        for (int i = 1; i <= main.dbControl.kelas.getKelasCount(); i++) {
            String namaKelas = main.dbControl.kelas.findKelas(i).getNamaKelas();
            model.addRow(new Object[]{(i + 3), "Siswa " + namaKelas, "Group ini berisi seluruh contact person dari orang tua/ wali siswa " + namaKelas});
            k = i + 3;
        }
        model.addRow(new Object[]{(k + 1), "Karyawan", "Group ini berisi seluruh contact person seluruh karyawan"});
        model.addRow(new Object[]{(k + 2), "Guru dan Karyawan", "Group ini berisi seluruh contact person dari seluruh guru dan karyawan"});
        model.addRow(new Object[]{(k + 3), "Siswa", "Group ini berisi seluruh contact person dari seluruh siswa"});
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        guru = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        tfGuru = new javax.swing.JTextField();
        jPanel5 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tableGuru = new javax.swing.JTable();
        siswa = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        tfSiswa = new javax.swing.JTextField();
        jPanel6 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tableSiswa = new javax.swing.JTable();
        karyawan = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        tfKaryawan = new javax.swing.JTextField();
        jPanel7 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        tableKaryawan = new javax.swing.JTable();
        group = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        tfGroup = new javax.swing.JTextField();
        jPanel8 = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        tableGroup = new javax.swing.JTable();

        setLayout(new java.awt.CardLayout());

        jLabel1.setText("Cari Nama :");

        jPanel5.setLayout(new java.awt.CardLayout());

        tableGuru.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "NIP", "Nama Guru", "No HP", "Jenjang"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tableGuru.getTableHeader().setReorderingAllowed(false);
        tableGuru.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                tableGuruMouseReleased(evt);
            }
        });
        jScrollPane1.setViewportView(tableGuru);
        tableGuru.getColumnModel().getColumn(0).setResizable(false);
        tableGuru.getColumnModel().getColumn(0).setPreferredWidth(20);
        tableGuru.getColumnModel().getColumn(1).setResizable(false);
        tableGuru.getColumnModel().getColumn(1).setPreferredWidth(120);
        tableGuru.getColumnModel().getColumn(2).setResizable(false);
        tableGuru.getColumnModel().getColumn(3).setResizable(false);
        tableGuru.getColumnModel().getColumn(3).setPreferredWidth(20);

        jPanel5.add(jScrollPane1, "card2");

        javax.swing.GroupLayout guruLayout = new javax.swing.GroupLayout(guru);
        guru.setLayout(guruLayout);
        guruLayout.setHorizontalGroup(
            guruLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(guruLayout.createSequentialGroup()
                .addGroup(guruLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(guruLayout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(tfGuru, javax.swing.GroupLayout.PREFERRED_SIZE, 271, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(guruLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, 565, Short.MAX_VALUE)))
                .addContainerGap())
        );
        guruLayout.setVerticalGroup(
            guruLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(guruLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(guruLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(tfGuru, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, 219, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Guru", guru);

        jLabel2.setText("Cari Nama :");

        jPanel6.setLayout(new java.awt.CardLayout());

        tableSiswa.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "NIS", "Nama Siswa", "Kelas", "Orang Tua / Wali", "No HP"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tableSiswa.getTableHeader().setReorderingAllowed(false);
        tableSiswa.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                tableSiswaMouseReleased(evt);
            }
        });
        jScrollPane2.setViewportView(tableSiswa);
        tableSiswa.getColumnModel().getColumn(0).setResizable(false);
        tableSiswa.getColumnModel().getColumn(0).setPreferredWidth(20);
        tableSiswa.getColumnModel().getColumn(1).setResizable(false);
        tableSiswa.getColumnModel().getColumn(1).setPreferredWidth(70);
        tableSiswa.getColumnModel().getColumn(2).setResizable(false);
        tableSiswa.getColumnModel().getColumn(2).setPreferredWidth(15);
        tableSiswa.getColumnModel().getColumn(3).setResizable(false);
        tableSiswa.getColumnModel().getColumn(4).setResizable(false);

        jPanel6.add(jScrollPane2, "card2");

        javax.swing.GroupLayout siswaLayout = new javax.swing.GroupLayout(siswa);
        siswa.setLayout(siswaLayout);
        siswaLayout.setHorizontalGroup(
            siswaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(siswaLayout.createSequentialGroup()
                .addGroup(siswaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(siswaLayout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(tfSiswa, javax.swing.GroupLayout.PREFERRED_SIZE, 271, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(siswaLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, 565, Short.MAX_VALUE)))
                .addContainerGap())
        );
        siswaLayout.setVerticalGroup(
            siswaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(siswaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(siswaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(tfSiswa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, 219, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Siswa", siswa);

        jLabel3.setText("Cari Nama :");

        jPanel7.setLayout(new java.awt.CardLayout());

        tableKaryawan.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nama Karyawan", "Alamat", "No HP"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tableKaryawan.getTableHeader().setReorderingAllowed(false);
        tableKaryawan.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                tableKaryawanMouseReleased(evt);
            }
        });
        jScrollPane3.setViewportView(tableKaryawan);
        tableKaryawan.getColumnModel().getColumn(0).setResizable(false);
        tableKaryawan.getColumnModel().getColumn(1).setResizable(false);
        tableKaryawan.getColumnModel().getColumn(2).setResizable(false);

        jPanel7.add(jScrollPane3, "card2");

        javax.swing.GroupLayout karyawanLayout = new javax.swing.GroupLayout(karyawan);
        karyawan.setLayout(karyawanLayout);
        karyawanLayout.setHorizontalGroup(
            karyawanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(karyawanLayout.createSequentialGroup()
                .addGroup(karyawanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(karyawanLayout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(tfKaryawan, javax.swing.GroupLayout.PREFERRED_SIZE, 271, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(karyawanLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, 565, Short.MAX_VALUE)))
                .addContainerGap())
        );
        karyawanLayout.setVerticalGroup(
            karyawanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(karyawanLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(karyawanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(tfKaryawan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, 219, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Karyawan", karyawan);

        jLabel4.setText("Cari Group :");

        jPanel8.setLayout(new java.awt.CardLayout());

        tableGroup.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "No", "Nama Group", "Diskripsi Group"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.Object.class, java.lang.Object.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tableGroup.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        tableGroup.getTableHeader().setReorderingAllowed(false);
        tableGroup.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                tableGroupMouseReleased(evt);
            }
        });
        jScrollPane4.setViewportView(tableGroup);
        tableGroup.getColumnModel().getColumn(0).setResizable(false);
        tableGroup.getColumnModel().getColumn(0).setPreferredWidth(5);
        tableGroup.getColumnModel().getColumn(1).setResizable(false);
        tableGroup.getColumnModel().getColumn(1).setPreferredWidth(100);
        tableGroup.getColumnModel().getColumn(2).setResizable(false);
        tableGroup.getColumnModel().getColumn(2).setPreferredWidth(300);

        jPanel8.add(jScrollPane4, "card2");

        javax.swing.GroupLayout groupLayout = new javax.swing.GroupLayout(group);
        group.setLayout(groupLayout);
        groupLayout.setHorizontalGroup(
            groupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(groupLayout.createSequentialGroup()
                .addGroup(groupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(groupLayout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(tfGroup, javax.swing.GroupLayout.PREFERRED_SIZE, 271, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(groupLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, 565, Short.MAX_VALUE)))
                .addContainerGap())
        );
        groupLayout.setVerticalGroup(
            groupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(groupLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(groupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(tfGroup, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, 219, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Group", group);

        add(jTabbedPane1, "card2");
    }// </editor-fold>//GEN-END:initComponents

    private void tableGroupMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableGroupMouseReleased
        int index = Integer.parseInt("" + tableGroup.getValueAt(tableGroup.getSelectedRow(), 0));
        data = new ArrayList();
        fromDatabase(index);
        String[] d = new String[data.size()];
        for (int i = 0; i < data.size(); i++) {
            d[i] = (String) data.get(i);
        }
        message.setNumber(d);
        tableGroup.clearSelection();
        pop.setVisible(false);
    }//GEN-LAST:event_tableGroupMouseReleased

    private void tableGuruMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableGuruMouseReleased
        data = new ArrayList();
        for (int i = tableGuru.getSelectedRows().length - 1; i > -1; i--) {
            data.add(tableGuru.getValueAt(tableGuru.getSelectedRows()[i], 3));
        }
        String[] d = new String[data.size()];
        for (int i = 0; i < data.size(); i++) {
            d[i] = "" + data.get(i);
        }
        message.setNumber(d);
        tableGuru.clearSelection();
        pop.setVisible(false);
    }//GEN-LAST:event_tableGuruMouseReleased

    private void tableSiswaMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableSiswaMouseReleased
        data = new ArrayList();
        for (int i = tableSiswa.getSelectedRows().length - 1; i > -1; i--) {
            data.add(tableSiswa.getValueAt(tableSiswa.getSelectedRows()[i], 5));
        }
        String[] d = new String[data.size()];
        for (int i = 0; i < data.size(); i++) {
            d[i] = "" + data.get(i);
        }
        message.setNumber(d);
        tableSiswa.clearSelection();
        pop.setVisible(false);
    }//GEN-LAST:event_tableSiswaMouseReleased

    private void tableKaryawanMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableKaryawanMouseReleased
        data = new ArrayList();
        for (int i = tableKaryawan.getSelectedRows().length - 1; i > -1; i--) {
            data.add(tableKaryawan.getValueAt(tableKaryawan.getSelectedRows()[i], 1));
        }
        String[] d = new String[data.size()];
        for (int i = 0; i < data.size(); i++) {
            d[i] = "" + data.get(i);
        }
        message.setNumber(d);
        tableKaryawan.clearSelection();
        pop.setVisible(false);
    }//GEN-LAST:event_tableKaryawanMouseReleased
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel group;
    private javax.swing.JPanel guru;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JPanel karyawan;
    private javax.swing.JPanel siswa;
    private javax.swing.JTable tableGroup;
    private javax.swing.JTable tableGuru;
    private javax.swing.JTable tableKaryawan;
    private javax.swing.JTable tableSiswa;
    private javax.swing.JTextField tfGroup;
    private javax.swing.JTextField tfGuru;
    private javax.swing.JTextField tfKaryawan;
    private javax.swing.JTextField tfSiswa;
    // End of variables declaration//GEN-END:variables

    public void fromDatabase(int index) {
        if (index < 4) {
            for (int i = 0; i < main.dbControl.guru.getGuruCount(); i++) {
                if (main.dbControl.guru.findGuruEntities().get(i).getIdJenjang() == index) {
                    data.add(main.dbControl.guru.findGuruEntities().get(i).getNoHp());
                }
            }
        } else if (index > 3 && index < 33) {
            for (int i = 0; i < main.dbControl.siswa.getSiswaCount(); i++) {
                if (main.dbControl.siswa.findSiswaEntities().get(i).getCodeKelas() == index + 1) {
                    data.add(main.dbControl.siswa.findSiswaEntities().get(i).getNoHp());
                }
            }
        } else if (index == 33) {
            for (int i = 0; i < main.dbControl.karyawan.getKaryawanCount(); i++) {
                data.add(main.dbControl.karyawan.findKaryawanEntities().get(i).getNoHp());
            }
        } else if (index == 34) {
            for (int i = 0; i < main.dbControl.karyawan.getKaryawanCount(); i++) {
                data.add(main.dbControl.karyawan.findKaryawanEntities().get(i).getNoHp());
            }
            for (int i = 0; i < main.dbControl.guru.getGuruCount(); i++) {
                data.add(main.dbControl.guru.findGuruEntities().get(i).getNoHp());
            }
        } else if (index == 35) {
            for (int i = 0; i < main.dbControl.siswa.getSiswaCount(); i++) {
                data.add(main.dbControl.siswa.findSiswaEntities().get(i).getNoHp());
            }
        }
    }

    private void initGroupActions() {
        tfGroup.getDocument().addDocumentListener(new DocumentListener() {

            public void insertUpdate(DocumentEvent e) {
                filterGroupTable(tfGroup.getText());
            }

            public void removeUpdate(DocumentEvent e) {
                filterGroupTable(tfGroup.getText());
            }

            public void changedUpdate(DocumentEvent e) {
                filterGroupTable(tfGroup.getText());
            }
        });
    }

    public void filterGroupTable(String text) {
        tableGroup.setModel(tableGroup.getModel());
        TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tableGroup.getModel());
        tableGroup.setRowSorter(sorter);
        if (text.trim().equals("")) {
            sorter.setRowFilter(null);
        } else {
            sorter.setRowFilter(RowFilter.regexFilter("(?i)" + text));
        }
    }

    private void initGuruActions() {
        tfGuru.getDocument().addDocumentListener(new DocumentListener() {

            public void insertUpdate(DocumentEvent e) {
                filterGuruTable(tfGuru.getText());
            }

            public void removeUpdate(DocumentEvent e) {
                filterGuruTable(tfGuru.getText());
            }

            public void changedUpdate(DocumentEvent e) {
                filterGuruTable(tfGuru.getText());
            }
        });
    }

    public void filterGuruTable(String text) {
        tableGuru.setModel(tableGuru.getModel());
        TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tableGuru.getModel());
        tableGuru.setRowSorter(sorter);
        if (text.trim().equals("")) {
            sorter.setRowFilter(null);
        } else {
            sorter.setRowFilter(RowFilter.regexFilter("(?i)" + text));
        }
    }

    private void initSiswaActions() {
        tfSiswa.getDocument().addDocumentListener(new DocumentListener() {

            public void insertUpdate(DocumentEvent e) {
                filterSiswaTable(tfSiswa.getText());
            }

            public void removeUpdate(DocumentEvent e) {
                filterSiswaTable(tfSiswa.getText());
            }

            public void changedUpdate(DocumentEvent e) {
                filterSiswaTable(tfSiswa.getText());
            }
        });
    }

    public void filterSiswaTable(String text) {
        tableSiswa.setModel(tableSiswa.getModel());
        TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tableSiswa.getModel());
        tableSiswa.setRowSorter(sorter);
        if (text.trim().equals("")) {
            sorter.setRowFilter(null);
        } else {
            sorter.setRowFilter(RowFilter.regexFilter("(?i)" + text));
        }
    }

    private void initKaryawanActions() {
        tfKaryawan.getDocument().addDocumentListener(new DocumentListener() {

            public void insertUpdate(DocumentEvent e) {
                filterKaryawanTable(tfKaryawan.getText());
            }

            public void removeUpdate(DocumentEvent e) {
                filterKaryawanTable(tfKaryawan.getText());
            }

            public void changedUpdate(DocumentEvent e) {
                filterKaryawanTable(tfKaryawan.getText());
            }
        });
    }

    public void filterKaryawanTable(String text) {
        tableKaryawan.setModel(tableKaryawan.getModel());
        TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tableKaryawan.getModel());
        tableKaryawan.setRowSorter(sorter);
        if (text.trim().equals("")) {
            sorter.setRowFilter(null);
        } else {
            sorter.setRowFilter(RowFilter.regexFilter("(?i)" + text));
        }
    }
}
